package com.bocloud.cmp.server.scheduler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.bocloud.cmp.entity.resource.CloudVendor;
import com.bocloud.cmp.interfaces.resource.CloudVendorService;
import com.bocloud.cmp.interfaces.resource.SyncService;
import com.bocloud.coordinator.cache.LeaderShip;

/**
 * 平台定时同步数据类
 * 
 * @author weiwei
 *
 */
@Component
public class PlatformSyncScheduler {

	@Autowired
	private CloudVendorService cloudVendorService;
	@Autowired
	private SyncService syncService;

	@Scheduled(cron = "${plarform.sync.schedule:0 0 0 * * ?}")
	protected void sync() {
		if (LeaderShip.isLeader()) {
			List<CloudVendor> vendors = this.cloudVendorService.listAll();
			for (CloudVendor vendor : vendors) {
				syncService.sync(vendor, 1L);
			}
		}
	}

}
